home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / MPW181-5 / _SETUP.1 / indigo_obuffer.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-21  |  3.3 KB  |  136 lines

  1. /* indigo_obuffer.cc
  2.  
  3.    Obuffer for Silicon Graphics Indigo written by
  4.    Tobias Bading (bading@cs.tu-berlin.de)
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20. #ifdef IRIX
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <errno.h>
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. #include <sys/ioctl.h>
  29. #include <iostream.h>
  30. extern "C" {
  31. #include <audio.h>
  32. }
  33.  
  34. #include "header.h"
  35. #include "obuffer.h"
  36. #include "args.h"
  37.  
  38. IndigoObuffer::IndigoObuffer (uint32 number_of_channels, MPEG_Args *maplay_args)
  39. {
  40. #ifdef DEBUG
  41.   if (!number_of_channels || number_of_channels > MAXCHANNELS)
  42.   {
  43.     cerr << "IndigoObuffer: number of channels has to be in [1, " <<  MAXCHANNELS << "] !\n";
  44.     exit (1);
  45.   }
  46. #endif
  47.   channels = number_of_channels;
  48.   for (int i = 0; i < number_of_channels; ++i)
  49.     bufferp[i] = buffer + i;
  50.  
  51.   // open an audio port and configure it:
  52.   ALconfig config;
  53.   if (!(config = ALnewconfig ()))
  54.   {
  55.     cerr << "ALnewconfig failed!\n";
  56.     exit (1);
  57.   }
  58.   ALsetwidth (config, AL_SAMPLE_16);
  59.   if (channels == 1)
  60.     ALsetchannels (config, AL_MONO);
  61.   else
  62.     ALsetchannels (config, AL_STEREO);
  63.   if (!(port = ALopenport ("MPEG audio player", "w", config)))
  64.   {
  65.     cerr << "can't allocate an audio port!\n";
  66.     exit (1);
  67.   }
  68.  
  69.   // set sample rate:
  70.   long pvbuffer[2] = { AL_OUTPUT_RATE, 0 };
  71.   pvbuffer[1] = maplay_args->MPEGheader->frequency ();
  72.   ALsetparams (AL_DEFAULT_DEVICE, pvbuffer, 2);
  73.   ALfreeconfig (config);
  74. }
  75.  
  76.  
  77. IndigoObuffer::~IndigoObuffer (void)
  78. {
  79.   while (ALgetfilled (port) > 0)
  80.     sleep (1);
  81.   ALcloseport (port);
  82. }
  83.  
  84.  
  85. void IndigoObuffer::append (uint32 channel, int16 value)
  86. {
  87. #ifdef DEBUG
  88.   if (channel >= channels)
  89.   {
  90.     cerr << "illegal channelnumber in IndigoObuffer::append()!\n";
  91.     exit (1);
  92.   }
  93.   if (bufferp[channel] - buffer >= OBUFFERSIZE)
  94.   {
  95.     cerr << "IndigoObuffer: buffer overflow!\n";
  96.     exit (1);
  97.   }
  98. #endif
  99.   *bufferp[channel] = value;
  100.   bufferp[channel] += channels;
  101. }
  102.  
  103. #ifdef SEEK_STOP
  104. void IndigoObuffer::clear_buffer(void)
  105. {
  106. }
  107.  
  108. void IndigoObuffer::set_stop_flag(void)
  109. {
  110. }
  111. #endif // SEEK_STOP
  112.  
  113. void IndigoObuffer::write_buffer (int)
  114. {
  115.   ALwritesamps (port, buffer, (long)(bufferp[0] - buffer));
  116.   for (int i = 0; i < channels; ++i)
  117.     bufferp[i] = buffer + i;
  118. }
  119.  
  120. Obuffer *create_obuffer(MPEG_Args *maplay_args)
  121. {
  122.     Obuffer *buffer;
  123.  
  124.     enum e_mode mode = maplay_args->MPEGheader->mode();
  125.    enum e_channels which_channels = maplay_args->which_c;
  126.  
  127.    if (mode == single_channel || which_channels != both)
  128.       buffer = new IndigoObuffer (1, maplay_args);
  129.    else
  130.       buffer = new IndigoObuffer (2, header);
  131.  
  132.    return(buffer);
  133. }
  134.  
  135. #endif // IRIX
  136.